package java_thinking.unit_9._9_4;

/**
 * @Description :
 * @author: cww
 * @DateTime: 2019-03-03 15:47
 */
interface CanFight {
    void fight();
}
interface CanSwim{
    void swim();
}
interface CanFly{
    void fly();
}
interface CanClimb{
    void climb();
}

class ActionCharacter {
    public void fight(){
        System.out.println("ActionCharacter.fight()");
    }
}

/**
 * 1.ActionCharacter基类中有fight方法，CanFight也有fight方法定义
 *  此时CanFight.fight()和ActionCharacter.fight()的特征签名是一样的，
 *  也就是说如果Hero默认没有覆盖fight方法，那么CanFight.fight()指向的就是ActionCharacter.fight()
 * 2.这里也无意间用到了类适配器模式，想要让源类使用各个接口的相关方法，但是ActionCharacter不能被改变，此时
 *   引入Hero继承ActionCharacter、实现接口，这样Hero就得以实现接口的方法并且继承ActionCharacter
 *   的方法
 */
class Hero extends ActionCharacter implements CanFight,CanSwim,CanFly, CanClimb{
    @Override
    public void swim(){
        System.out.println("swim");
    }
    @Override
    public void fly(){
        System.out.println("fly");}

    @Override
    public void climb() {
        System.out.println("CanClimb");
    }

    /**
     * 这里如果覆写了就会用Hero自己的fight方法，如果没写，那么CanFight的fight方法就会用父类的！！
     */
/*    @Override
    public void fight(){
        System.out.println("fight");
    }*/
}

class Adventure {
    public static void t(CanFight canFight){
        canFight.fight();
    }
    public static void u(CanSwim canSwim){
        canSwim.swim();
    }
    public static void v(CanFly canFly){
        canFly.fly();
    }
    public static void w(ActionCharacter actionCharacter){
        actionCharacter.fight();
    }
    public static void x(CanClimb canClimb){
        canClimb.climb();
    }

    public static void main(String[] args) {
        Hero hero = new Hero();
        t(hero);
        u(hero);
        v(hero);
        w(hero);
        x(hero);
    }
}